package com.huluspace.military.controller;


import com.huluspace.military.dto.UnifiedResponse;
import com.huluspace.military.model.MilitaryEvent;
import com.huluspace.military.model.Region;
import com.huluspace.military.service.MapService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/map")
public class MilitaryEventController {

  private final MapService mapService;
  public MilitaryEventController(MapService mapService) {
    this.mapService = mapService;
  }

  @PostMapping("/report")
  public UnifiedResponse<String> reportEvent(@RequestBody MilitaryEvent event) {
    try{
      mapService.addEvent(event);
    }catch(RuntimeException ex){
      return UnifiedResponse.error(1, "事件上报失败");
    }
    return UnifiedResponse.success("事件上报成功", null);
  }

  // GET方式不支持请求体，改用POST
  @PostMapping("/events")
  public UnifiedResponse<List<MilitaryEvent>> getEvents(@RequestBody Region region) {
    try {
      List<MilitaryEvent> events = mapService.getEvents(region);
      return UnifiedResponse.success("获取事件成功", events);
    } catch (RuntimeException ex) {
      return UnifiedResponse.error(1, "获取事件失败");
    }
  }

}
